//
//  Stage.cpp
//  airfight
//
//  Created by aaron more on 12-9-12.
//  Copyright (c) 2012年 moonriver. All rights reserved.
//

#include <iostream>
#include "Stage.h"

Stage::Stage()
:m_stageID(0)
,m_name("")
,m_distance(0)
,m_front(NULL)
,m_rear(NULL)
{
    enemy_Dict = CCDictionary::create();
    enemy_Dict->retain();
}

Stage::~Stage()
{
    CC_SAFE_RELEASE(enemy_Dict);
}

CCArray* Stage::getStartEnemyIDs(int p_start)
{
    CCObject* tmp = enemy_Dict->objectForKey(p_start);
    
    if(tmp){
        return (CCArray*)tmp;
    }else{
        return NULL;
    }
}

void Stage::addStartEnemyID(StageEnemy *p_enemy)
{
    int startY = p_enemy->getStartY();
    CCArray* ids = getStartEnemyIDs(startY);
    if( !ids )
    {
        ids = CCArray::create();
        ids->retain();
    }
    
    ids->addObject(p_enemy);
    enemy_Dict->setObject(ids, startY);
}

CCArray* Stage::getAllStageEnemies()
{
    CCArray *stageEnemies = CCArray::create();
    stageEnemies->retain();
    CCDictElement *enemyElements = NULL;

    CCDICT_FOREACH(enemy_Dict, enemyElements)
    {
        CCArray *enemyArray = (CCArray*)enemyElements->getObject();
        CCObject *stageEnemyObject = NULL;
        CCARRAY_FOREACH(enemyArray, stageEnemyObject)
        {
            CC_BREAK_IF(!stageEnemyObject);
            StageEnemy *stageEnemy = (StageEnemy*)stageEnemyObject;
            stageEnemies->addObject(stageEnemy);
        }
    }
    return stageEnemies;
    
}
